package com.mtsmda.oracleOfficialTutorialJAVA7.chapter1;

public class BranchingEx {

	private static int count;

	private static final String SIMPLE_CONTINUE = "SIMPLE_CONTINUE";
	private static final String LABELED_CONTINUE = "LABELED_CONTINUE";
	private static final String SIMPLE_BREAK = "SIMPLE_BREAK";
	private static final String LABELED_BREAK = "LABELED_BREAK";

	public static void main(String[] args) {
		int[] io = new int[19];
		for (int i = 0; i < io.length; i++) {
			io[i] = (int) Math.random();
		}

		for (int i = 0; i < io.length; i++) {
			if (i == 5) {
				System.out.println("i = 5");
				if (true) {
					System.out.println("true");
					break;
				}
			}
			System.out.println(i);
		}
		System.out.println("end\n");

		breakLabel: for (int i = 0; i < io.length; i++) {
			if (i == 5) {
				System.out.println("i = 5");
				if (true) {
					System.out.println("true");
					break breakLabel;
				}
			}
			System.out.println(i);
		}
		System.out.println("end2\n");

		// 0.1.2 - 80
		new BranchingEx().labeledContinueAndBreak2("");
		new BranchingEx().labeledContinueAndBreak2(SIMPLE_BREAK);
		new BranchingEx().labeledContinueAndBreak2(SIMPLE_CONTINUE);
		new BranchingEx().labeledContinueAndBreak2(LABELED_BREAK);
		new BranchingEx().labeledContinueAndBreak2(LABELED_CONTINUE);

	}

	private void labeledContinueAndBreak(String param) {
		System.out.println("_____________" + ++count + "________________");
		System.out.println("BEGIN - labeledContinueAndBreak - " + param);

		int[][][] three = { { { 1, 2, 5 }, { 58, 95, 80, 77 } },
				{ { 951, 753, 953, 1235, 7643 } } };
		labeledB: labeledC: for (int i = 0; i < three.length; i++) {
			for (int j = 0; j < three[i].length; j++) {
				for (int k = 0; k < three[i][j].length; k++) {
					if (i == 0 && j == 1 && k == 2) {
						if (param.equals(LABELED_BREAK)) {
							break labeledB;
						}
						if (param.equals(LABELED_CONTINUE)) {
							continue labeledC;
						}
						if (param.equals(SIMPLE_BREAK)) {
							break;
						}
						if (param.equals(SIMPLE_CONTINUE)) {
							continue;
						}
					}
					System.out.println(i + "." + j + "." + k + " - "
							+ three[i][j][k]);
				}
			}
		}
		System.out.println("END - labeledContinueAndBreak");
		System.out.println("_____________________________");
	}

	private void labeledContinueAndBreak2(String param) {
		System.out.println("_____________" + ++count + "________________");
		System.out.println("BEGIN - labeledContinueAndBreak - " + param);

		int[][] three = { { 1, 2, 5 }, { 58, 95, 80, 77 },
				{ 951, 753, 953, 1235, 7643 } };
		labeledB: labeledC: for (int i = 0; i < three.length; i++) {
			for (int j = 0; j < three[i].length; j++) {
				if (i == 0 && j == 1) {
					if (param.equals(LABELED_BREAK)) {
						break labeledB;
					}
					if (param.equals(LABELED_CONTINUE)) {
						continue labeledC;
					}
					if (param.equals(SIMPLE_BREAK)) {
						break;
					}
					if (param.equals(SIMPLE_CONTINUE)) {
						continue;
					}
				}
				System.out.println(i + "." + j + " - " + three[i][j]);
			}
		}
		System.out.println("END - labeledContinueAndBreak");
		System.out.println("_____________________________");
	}

}